package com.tianyang.yukuaifuzs.business.auth.view;

import androidx.viewpager.widget.ViewPager;

import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.base.BaseTitleActivity;
import com.tianyang.yukuaifuzs.business.auth.adapter.MerchantInfoManageAdapter;
import com.tianyang.yukuaifuzs.common.bean.TabEntity;
import com.tianyang.yukuaifuzs.module.tablelayout.CommonTabLayout;
import com.tianyang.yukuaifuzs.module.tablelayout.CustomTabEntity;
import com.tianyang.yukuaifuzs.module.tablelayout.listener.OnTabSelectListener;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Description：商户信息管理
 * Created by xyj on 2024/3/8
 */
public class MerchantInfoManageActivity extends BaseTitleActivity {

    @BindView(R.id.tabLayout)
    CommonTabLayout vTabLayout;
    @BindView(R.id.merchantManageVp)
    ViewPager merchantManageVp;

    private MerchantInfoManageAdapter vMerchantInfoManageAdapter;

    private int mCurrentIndex = 0;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_merchant_info_manage;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("商户信息管理");

        ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
        mTabEntities.add(new TabEntity("入网中", 0, 0));
        mTabEntities.add(new TabEntity("审核中", 0, 0));
        mTabEntities.add(new TabEntity("待授权", 0, 0));
        mTabEntities.add(new TabEntity("已拒绝", 0, 0));
        vTabLayout.setTabData(mTabEntities);
        vTabLayout.setCurrentTab(mCurrentIndex);

        vMerchantInfoManageAdapter = new MerchantInfoManageAdapter(getSupportFragmentManager());
        merchantManageVp.setAdapter(vMerchantInfoManageAdapter);
        merchantManageVp.setCurrentItem(mCurrentIndex);
        merchantManageVp.setOffscreenPageLimit(3);
    }

    @Override
    protected void setListener() {
        super.setListener();
        vTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (mCurrentIndex != position) {
                    mCurrentIndex = position;
                    merchantManageVp.setCurrentItem(mCurrentIndex);
                }
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        merchantManageVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (mCurrentIndex != position) {
                    mCurrentIndex = position;
                    vTabLayout.setCurrentTab(mCurrentIndex);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }
}
